package com.lanchetech.merchant.service.impl;

import com.lanchetech.dao.MerchantMapper;
import com.lanchetech.entity.Merchant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

public class MerchantCustomUserService implements UserDetailsService { //1
    @Autowired
    MerchantMapper merchantMapper;

    @Override
    public UserDetails loadUserByUsername(String username) { //2
        Merchant merchant = merchantMapper.findOneByUsername(username);
        if (merchant == null) {
            throw new UsernameNotFoundException("管理员不存在");
        }

        return merchant;
    }

}
